refactor: introduce RlmSession, dissolve operations/, enforce adapter…#30
refactor: introduce RlmSession, dissolve operations/, enforce adapter…#30SaschaOnTour merged 15 commits intomainfrom
Conversation
… thinness
CLI and MCP handlers now route every tool call through a single
`application::session::RlmSession` that owns the `Database` handle
and `Config`. Adapters do nothing but parse arguments, call one
session method, and emit the result through their formatter.
Key changes:
- New `application::session::RlmSession`: one method per tool
(search, read_symbol, read_section, overview, refs, context,
deps, scope, partition, summarize, diff, files, verify, supported,
stats, quality, replace_preview/apply, delete, insert, extract).
Static methods for `index_project` and `supported`.
- New `application::edit::write_dispatch`: shared orchestration
(op → reindex → splice → record savings) for replace / delete /
insert / extract. Adapters build an input struct and call.
- New `application::query::read`: symbol + section logic lifted
out of both adapters. MCP no longer imports `domain::chunk::Chunk`.
- New `application::middleware` (moved from `interface::shared`):
`record_operation` / `record_file_query` / `record_symbol_query`.
- Stats/savings/quality consolidated: MCP `stats(savings?, since?)`
replaces the standalone `savings` tool; new MCP `quality` tool
mirrors `rlm quality`.
- `application::savings` and `application::index::output` are now
the physical homes for what used to live under `operations/`.
- `src/operations/` deleted in full. `operations::refs::get_refs`
was dead code (only called by its own tests); removed.
Rustqual enforcement:
- New `[[architecture.pattern]] adapters_no_direct_infrastructure`
forbids `crate::db::`, `crate::ingest::`, `crate::application::index::`,
`crate::domain::{chunk,file,reference}::`, and
`crate::application::savings::` inside every CLI/MCP handler file.
Test-only helpers are exempt.
- `[architecture.layers.application]` no longer lists
`src/operations/**`; the transitional layer is gone.
Quality gates:
- cargo build: clean
- cargo clippy --all-targets -- -D warnings: clean
- cargo nextest run: 825 passed, 6 skipped, 0 failed
(2 tests removed with the dead `operations::refs::get_refs`)
- rustqual --findings: 0
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors CLI + MCP adapters to route all tool execution through a single application::session::RlmSession, dissolves the legacy operations/ façade, and adds 0.5.0 features (test-impact, native post-write check, extract/delete tools, search projection, parser-version stamping, and setup defaults).
Changes:
- Introduces
RlmSession+ application-layer middleware/dispatchers so adapters become thin (parse → session call → emit). - Consolidates MCP/CLI surfaces (adds MCP
quality, foldssavingsintostats, adds write toolsdelete/extract, adds search projection flags). - Adds new indexing/parser capabilities and safety checks (enum variants as chunks, parser-version DB stamping, native
cargo checkin write envelopes, test-impact + similar-symbol hints).
Reviewed changes
Copilot reviewed 88 out of 99 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/mcp_tests.rs | Updates MCP tool list expectations and stats/quality/savings consolidation tests. |
| tests/cli_mcp_parity_tests.rs | New test ensuring CLI↔MCP command/argument parity. |
| src/operations/refs_tests.rs | Removes dead operations::refs tests (module removed). |
| src/operations/refs.rs | Removes dead operations::refs API (module removed). |
| src/operations/mod.rs | Removes transitional operations re-export façade. |
| src/mcp/tools.rs | Extends MCP tool schemas (search fields, parent disambiguation, stats params, quality tool, delete/extract params). |
| src/mcp/tool_handlers_tests.rs | Updates MCP handler tests to use RlmSession instead of Database. |
| src/mcp/tool_handlers_read.rs | Refactors MCP read handler to delegate to application query::read via session. |
| src/mcp/tool_handlers_query.rs | Refactors MCP query handlers (search/overview/refs/files) to call session + adds search projection. |
| src/mcp/tool_handlers_index.rs | Refactors MCP index handler to call RlmSession::index_project and sandbox path. |
| src/mcp/tool_handlers_edit.rs | Refactors MCP write handlers to use application write_dispatch via session; adds delete/extract. |
| src/mcp/tool_handlers.rs | Updates exports for new/renamed MCP handlers. |
| src/mcp/server_tests.rs | Updates MCP server tests to import application-layer modules (no operations). |
| src/mcp/server_helpers_tests.rs | Updates MCP helper tests for session-based open behavior. |
| src/mcp/server_helpers.rs | Replaces DB factories with session factories and keeps output guarding helpers. |
| src/main.rs | Updates CLI command wiring for new flags and code-source resolution. |
| src/lib.rs | Removes pub mod operations. |
| src/interface/shared/mod.rs | Removes old interface shared middleware module. |
| src/interface/mod.rs | Updates interface docs and removes shared module export. |
| src/interface/cli/setup/orchestrator.rs | Adds new setup step for .rlm/config.toml output format. |
| src/interface/cli/setup/mod.rs | Wires in config_format module. |
| src/interface/cli/setup/config_format_tests.rs | Tests for new setup step that writes [output] format = "toon". |
| src/interface/cli/setup/config_format.rs | New setup step ensuring TOON default format in .rlm/config.toml. |
| src/interface/cli/setup/claude_md_tests.rs | Adds coverage for expanded CLAUDE.local.md template content. |
| src/interface/cli/setup/claude_md.rs | Refactors template into a const body and expands guidance sections. |
| src/ingest/code/rust_tests.rs | Adds tests for Rust enum-variant chunk extraction. |
| src/ingest/code/rust_nested.rs | New shared nested-chunk extractor used by Rust impl methods + enum variants. |
| src/ingest/code/rust_impl_methods.rs | Refactors impl-method extraction to use shared nested extractor. |
| src/ingest/code/rust_enum_variants.rs | New Rust enum-variant extraction module. |
| src/ingest/code/rust.rs | Adds enum-variant extraction pass when indexing Rust. |
| src/ingest/code/mod.rs | Registers new Rust ingest helper modules. |
| src/error.rs | Adds AmbiguousSymbol error type + candidate rendering. |
| src/domain/savings.rs | Updates docs to point savings implementation to application::savings. |
| src/domain/chunk.rs | Adds ChunkKind::EnumVariant and string conversions. |
| src/db/parser_version_tests.rs | Tests parser-version reconciliation and hash-clearing behavior. |
| src/db/parser_version.rs | Adds parser-version stamping + hash reset on mismatch. |
| src/db/mod.rs | Exposes new parser_version module. |
| src/db/migrations/mod.rs | Adds migration 004 for meta table. |
| src/db/migrations/004_meta.sql | New migration creating meta table. |
| src/db/connection.rs | Runs parser-version reconcile on DB open and removes open_if_exists. |
| src/config.rs | Adds [edit] settings controlling post-write native checks. |
| src/cli/helpers.rs | Adds resolve_code to support --code/--code-stdin/--code-file. |
| src/cli/handlers_util.rs | Refactors utility CLI handlers to delegate to RlmSession. |
| src/cli/commands.rs | Adds --fields to search; adds --parent, delete/extract commands, and code-source flags for writes. |
| src/application/symbol/test_impact_analyze.rs | New aggregation layer for test-impact output in write envelopes. |
| src/application/symbol/similar_symbols_tests.rs | Tests for new similar-symbol suggestion logic. |
| src/application/symbol/similar_symbols.rs | Adds Levenshtein-based similar symbol suggestions for write responses. |
| src/application/symbol/mod.rs | Exposes new symbol-analysis modules. |
| src/application/session_tests.rs | Placeholder for RlmSession unit tests (integration via CLI/MCP tests). |
| src/application/savings/savings_tests.rs | Splits legacy savings tests into dedicated file. |
| src/application/savings/savings_fixtures_tests.rs | Shared fixture for savings tests. |
| src/application/savings/mod.rs | Adds delete savings model and keeps savings APIs in application layer. |
| src/application/query/stats.rs | Adds unified stats_dispatch + quality_dispatch used by both adapters. |
| src/application/query/search.rs | Adds FieldsMode projection, improves FTS sanitizer semantics, makes hit content optional. |
| src/application/query/read_tests.rs | Placeholder for query::read unit tests. |
| src/application/query/read.rs | New unified read symbol/section logic shared by CLI + MCP (incl. savings recording). |
| src/application/query/mod.rs | Registers new read module and removes legacy migration docs. |
| src/application/mod.rs | Exposes new application modules (middleware/savings/session). |
| src/application/middleware/savings_recorder_tests.rs | Renames and updates middleware tests to new module names. |
| src/application/middleware/savings_recorder_scoped_tests.rs | Adds scoped/symbol-files savings middleware tests. |
| src/application/middleware/savings_recorder.rs | Moves savings middleware into application and unifies minimal JSON serialization. |
| src/application/middleware/response_tests.rs | Tests for new OperationResponse DTO. |
| src/application/middleware/response.rs | New shared response DTO (minified JSON + token count). |
| src/application/middleware/request_tests.rs | Tests for new request-side DTOs (OperationMeta, AlternativeCost). |
| src/application/middleware/request.rs | New request-side DTOs used by middleware/dispatchers. |
| src/application/middleware/mod.rs | New application middleware module exporting request/response/recorder. |
| src/application/middleware/fixtures_tests.rs | Shared fixtures for middleware tests. |
| src/application/index/output_tests.rs | Tests for index output DTO conversion/serialization. |
| src/application/index/output.rs | Fixes test module path rename for index output. |
| src/application/index/mod.rs | Exposes IndexOutput and augments write reindex envelope with build/test-impact. |
| src/application/edit/write_dispatch.rs | New shared write dispatch (replace/delete/insert/extract) used by CLI + MCP. |
| src/application/edit/savings_hooks.rs | Centralizes write-side savings recording hooks. |
| src/application/edit/replacer_tests.rs | Updates replacer preview signature to include optional parent. |
| src/application/edit/replacer_edge_tests.rs | Adds ambiguous-symbol tests and updates replace signature. |
| src/application/edit/native_check_tests.rs | Tests for native checker (cargo check) integration. |
| src/application/edit/native_check.rs | New native post-write checker implementation and diagnostic parsing. |
| src/application/edit/mod.rs | Registers new edit modules (extractor/native_check/write_dispatch/etc.). |
| src/application/edit/extractor_tests.rs | Tests for new extract write primitive. |
| src/application/edit/extractor.rs | New extract implementation moving symbols between files with validation. |
| src/application/dto/chunk_dto.rs | Adds DTO mapping for EnumVariant. |
| src/application/content/mod.rs | Removes legacy migration docs from module header. |
| rustqual.toml | Adds architecture rule preventing adapter leakage into DB/ingest/index/domain and removes operations layer. |
| README.md | Adds performance section and updates CLI command docs for new features. |
| Cargo.toml | Bumps crate version to 0.5.0. |
| Cargo.lock | Updates lockfile version entry for 0.5.0. |
| CHANGELOG.md | Adds detailed 0.5.0 release notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 88 out of 99 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 88 out of 99 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 88 out of 99 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 88 out of 99 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 88 out of 99 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 89 out of 100 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 90 out of 101 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 90 out of 101 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 91 out of 101 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 91 out of 101 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 91 out of 101 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 91 out of 101 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
application::session::RlmSession— adapters no longer touchDatabase,Config,ensure_index,staleness, or the savingsrecorder directly.
adapters_no_direct_infrastructureforbids raw DB / ingest /domain-entity / index-orchestration / savings imports inside any
CLI or MCP handler file.
stats,savings, andqualitynow shareapplication::query::stats::{stats_dispatch, quality_dispatch}.The standalone MCP
savingstool is gone (stats(savings=true, since=…)replaces it); a new MCP
qualitytool mirrorsrlm quality.replace/delete/insert/extractorchestrationout of both adapters into
application::edit::write_dispatch(op → reindex → splice → record savings). CLI and MCP handlers are
now three-line wrappers.
interface::shared::*toapplication::middleware::*(where itsemantically belongs — it's application logic adapters route
through, not an interface concern).
src/operations/:savingsmoved toapplication::savings,IndexOutputmoved toapplication::index::output,get_refsremoved as dead code.pub mod operationsis gone fromlib.rs.Why
src/cli/andsrc/mcp/each used to carry ~100 lines of identicalorchestration (open config + DB, refresh staleness, run op, splice
envelope, record savings). Drift between the two kept surfacing in
dogfooding — features added on one side silently missed the other.
Rustqual now refuses this class of leak at the import level: both
adapters are provably reduced to argument parsing + one session call
qual:allow(architecture)with a reason, and the CI gate makes that conspicuous.
Notable consequences
src/operations/no longer exists. External consumers ofcrate::operations::*need to switch tocrate::application::*(all symbols still exist at their real homes). Internal callers
are already migrated.
savingsremoved,qualityadded.cli_mcp_parity_testswhitelists both zero now — every shared command maps 1:1 on both
surfaces.
Database::open_if_existswas dead after the session refactor andhas been removed.
operations::refs::get_refs(they tested thedead wrapper, not the live refs path, which is covered by the
existing
RefsQueryintegration tests).Test plan
cargo buildcargo clippy --all-targets -- -D warningscargo fmt --checkcargo nextest run— 825 passed, 6 skipped, 0 failedrustqual --findings— 0 findingsrlm mcp+ invokestats,quality,replace,extractthrough a client to confirm tool shapes